*** This Do-File replicates all figures and tables from the article
***	A Matter of Trust - How Political and Social Trust relate to the Acceptance of Covid-19 Policies in Germany
*** Sebastian Jäckle, Eva-Maria Trüdinger, Achim Hildebrandt, Uwe Wagschal

* version: 09.11.2021

clear all
version 14.2

* additional packages (need to be loaded only if not already exist)
* ssc install outreg2, replace
* ssc install estout, replace
* ssc install coefplot, replace
* ssc install splitvallabels
* ssc install blindschemes, replace
* ssc install interflex, replace

set scheme plottigblind

* Here you need to set your path to the "Replication"-folder
*cd "YOURPATH\Replication"

* Wave 1 (May 7-17 2020)

use "data\corona_wave_1.dta"


* change missing codes 0 --> .

	mvdecode v_556, 	mv(0)
	mvdecode v_557, 	mv(0)
	mvdecode v_344, 	mv(0)
	mvdecode v_42, 		mv(0)
	mvdecode v_342,	 	mv(0)
	mvdecode v_498, 	mv(0)
	mvdecode v_502_a, 	mv(0)
	mvdecode geschlecht,mv(0)
	mvdecode v_505, 	mv(0)
	mvdecode v_363, 	mv(0)
	mvdecode v_364,		mv(0)
	mvdecode v_375, 	mv(0)
	mvdecode v_376, 	mv(0)
	mvdecode v_377, 	mv(0)
	mvdecode v_378, 	mv(0)
	mvdecode v_379, 	mv(0)
	mvdecode v_167,		mv(0)
	mvdecode v_172,		mv(0)
	mvdecode v_173,		mv(0)

* gender including non-binary
	gen gender = geschlecht
	
* gender = non-binary --> .
	mvdecode geschlecht, mv(3)
	
* still at school --> .
	mvdecode v_505, mv(1)

* recode & calculate variable and label values
	
	* dependent variable: acceptence of anti-Covid-19 policies
	gen acceptance_measures = -(v_556 - 6)
	
	* healthstate
	recode v_498 (1=5) (2=4) (3=3) (4=2) (5=1), gen(healthstate)
	label define healthstate 1 "very bad" 5 "very good"
	label value healthstate healthstate
	
	* incomeloss
	recode v_172 (1=5) (2=4) (3=3) (4=2) (5=1), gen(incomenow)
	label define incomenow 1 "find it very difficult to make ends meet" 5 "can live very comfortably on the income"
	label value incomenow incomenow

	recode v_173 (1=5) (2=4) (3=3) (4=2) (5=1), gen(incomebefore)
	label define incomebefore 1 "find it very difficult to make ends meet" 5 "can live very comfortably on the income"
	label value incomebefore incomebefore

	gen incomeloss = incomebefore-incomenow

	* householdsize 3+
	recode v_502_a (1/2=0) (3/31=1), gen(hh3andmore)
	label define hh3andmore 0 "householdsize < 3" 1 "householdsize >= 3"
	label values hh3andmore hh3andmore
	
	* male
	tab geschlecht, gen(n)
	rename n1 male
	label define male 0 "female" 1 "male"
	label value male male
	
	* gender (including non-binary)
	label define gender 1 "male" 2 "female" 3 "non-binary" 
	label values gender gender
	
	* age
	gen age = 2020 - v_496
	
	* highest educational attainment
	recode v_505 (2/3=1)(4=2)(5=3) (6=4) (7=5), gen (v_505_a)
	label define edu 1 "School dropout & Hauptschulabschluss (ISCED 2)" 2 "Mittlere Reife (ISCED 2)" 3 "Fachhochschulreife (ISCED 3)" 4 "Abitur            (ISCED 3)" 5 "University degree (ISCED 5a)"
	label value v_505_a edu
	
	tab v_505_a, gen(p)
	rename p1 ohne_hauptschule
	rename p2 mittlere_reife
	rename p3 fachhochschulreife
	rename p4 abitur
	rename p5 studium

	* political trust
		* precheck for index construction
		alpha v_363 v_364
		
		* Index using the mean of v_363 and v_364 (standardized to a 1-9-scale)
		gen poltrust = ((v_363 + v_364)/2)*2-1
	
	
	* authoritarianism
		* precheck for index construction
		pwcorr v_375-v_379, obs sig
		
		factor v_375-v_379
		rotate
		estat kmo
		
		alpha v_375-v_379 
		
		* index using the mean of the five authoritarianism questions
		gen auto = (v_375 + v_376 + v_377 + v_378 + v_379)/5
		
		
	* voting intention
		label define vote_intent 1 "CDU/CSU" 2 "SPD" 3 "Left Party" 4 "Greens" 5 "FDP" 6 "AfD" 7 "Others" 8 "Would not vote" 9 "Not eligible to vote"
		label values v_167 vote_intent
	
	* level-2 variables:
		
		* infection rates last 7/14/30 days | since January 2020 per 100,000 inhabitants
		gen inf_7tage_rel_100k = inf_7tage_rel*100000
		gen inf_14tage_rel_100k = inf_14tage_rel*100000
		gen inf_30tage_rel_100k = inf_30tage_rel*100000
		gen inf_seit_jan_rel_100k = inf_seit_jan_rel*100000
		
		* Covid-19 related deaths last 7/14/30 days | since January 2020 per 100,000 inhabitants
		gen tot_7tage_rel_100k = tot_7tage_rel*100000
		gen tot_14tage_rel_100k = tot_14tage_rel*100000
		gen tot_30tage_rel_100k = tot_30tage_rel*100000
		gen tot_seit_jan_rel_100k = tot_seit_jan_rel*100000
		
		* log distance hotspot
		gen dist_hotspot_log = log(dist_hotspot)
		
		* GDP per capita
		gen gdp_pc_17 = bip_17/bev_17
		
	* federal state
	gen bundesland_NUTS = substr(NUTS3,1,3)
	encode bundesland_NUTS, gen(bundesland)
	#delimit ;
	label define bundesland 
		1 "Baden-Wuerttemberg" 
		2 "Bavaria"
		3 "Berlin"
		4 "Brandenburg"
		5 "Bremen"
		6 "Hamburg"
		7 "Hesse"
		8 "Mecklenburg-Vorpommern"
		9 "Lower-Saxony"
		10 "North Rhine-Westpahila"
		11 "Rhineland-Palatinate"
		12 "Saarland"
		13 "Saxony"
		14 "Saxony-Anhalt"
		15 "Schleswig-Holstein"
		16 "Thuringia"	, modify ;
			#delimit cr
	label values bundesland bundesland
			
* label variables
	label variable acceptance_measures 		"Acceptance of policies to combat Covid-19"
	label variable poltrust 				"Political trust"
	label variable v_344 					"Social trust"
	label variable auto 					"Authoritarianism"
	label variable v_42 					"Left = 1; Right = 11"
	label variable v_167					"Voting intention"
	label variable v_342					"Political interest"
	label variable healthstate 				"Overall health status"
	label variable incomeloss				"Loss of income"
	label variable hh3andmore				"Household 3+ (dummy)"
	label variable male						"Male"
	label variable gender					"Gender"
	label variable age						"Age"
	label variable v_505_a					"Highest educational attainment"
	label variable ohne_hauptschule 		"School dropout/Hauptschulabschluss (ISCED 2)"
	label variable mittlere_reife			"Mittlere Reife (ISCED 2)"
	label variable fachhochschulreife  		"Fachhochschulreife (ISCED 3)"
	label variable abitur 					"Abitur (ISCED 3)"
	label variable studium					"University degree (ISCED 5a)"
	label variable inf_7tage_rel_100k		"# Covid-19 cases last 7 days per 100,000 inhabitants"
	label variable inf_14tage_rel_100k		"# Covid-19 cases last 14 days per 100,000 inhabitants"
	label variable inf_30tage_rel_100k		"# Covid-19 cases last 30 days per 100,000 inhabitants"
	label variable inf_seit_jan_rel_100k	"# Covid-19 cases since January 2020 per 100,000 inhabitants"
	label variable tot_7tage_rel_100k		"# Covid-19 deaths last 7 days per 100,000 inhabitants"
	label variable tot_14tage_rel_100k		"# Covid-19 deaths last 14 days per 100,000 inhabitants"
	label variable tot_30tage_rel_100k		"# Covid-19 deaths last 30 days per 100,000 inhabitants"
	label variable tot_seit_jan_rel_100k	"# Covid-19 deaths since January 2020 per 100,000 inhabitants"
	label variable dist_hotspot				"Distance to nearest hotspot (in km)"
	label variable dist_hotspot_log			"Log distance to nearest hotspot (in km)"
	label variable alq_18					"Unemployment rate (2018, in %)"
	label variable alq_19					"Unemployment rate (2019, in %)"
	label variable gdp_pc_17				"GDP per capita (2017, in thousand Euro)"
	label variable bundesland				"Federal state"

*keep 
	#delimit ;
	keep 	acceptance_measures 	
			poltrust				
			v_344					
			auto					
			v_42					
			v_167					
			v_342					
			healthstate				
			incomeloss	
			incomenow
			hh3andmore				
			male
			gender
			age						
			v_505_a					
			ohne_hauptschule		
			mittlere_reife			
			fachhochschulreife		
			abitur					
			studium					
			inf_7tage_rel_100k		
			inf_14tage_rel_100k		
			inf_30tage_rel_100k		
			inf_seit_jan_rel_100k	
			tot_7tage_rel_100k		
			tot_14tage_rel_100k		
			tot_30tage_rel_100k		
			tot_seit_jan_rel_100k	
			dist_hotspot
			dist_hotspot_log
			alq_18					
			alq_19					
			gdp_pc_17
			NUTS3 
			bundesland;
			#delimit cr
	
* Missing Table --> Table O1
misstable summ	
	
* generate filter variable for no missing cases in the following regression models

	gen complete_cases = 0
	
	#delimit ;
	replace complete_cases = 1 if 	acceptance_measures != . &
								poltrust				!= . &
								v_344					!= . &
								auto					!= . &
								v_42					!= . &
								v_42					!= .b&
								v_342					!= . &
								healthstate				!= . &
								incomeloss				!= . &
								hh3andmore				!= . &
								male					!= . &
								age						!= . &
								v_505_a					!= . &
								ohne_hauptschule		!= . &
								mittlere_reife			!= . &
								fachhochschulreife		!= . &
								abitur					!= . &
								studium					!= . &
								inf_7tage_rel_100k		!= . &
								inf_14tage_rel_100k		!= . &
								inf_30tage_rel_100k		!= . &
								inf_seit_jan_rel_100k	!= . &
								tot_7tage_rel_100k		!= . &
								tot_14tage_rel_100k		!= . &
								tot_30tage_rel_100k		!= . &
								tot_seit_jan_rel_100k	!= . &
								dist_hotspot			!= . &
								alq_18					!= . &
								alq_19					!= . &
								gdp_pc_17				!= . &
								NUTS3					!= "" ;
				#delimit cr


				
				
	** correlation social-political trust
	corr poltrust v_344 if complete_cases == 1
	
* Standardization of survey-variables 0-10
	gen st_acceptance_measures 	= (acceptance_measures - 1)*10/4
	gen st_poltrust 			= (poltrust - 1)*10/8
	gen st_v_344				= (v_344 - 1) * 10/6
	gen st_auto					= (auto - 1) * 10/4
	gen st_v_42					= (v_42 - 1) * 10/10
	gen st_v_342				= (v_342 - 1) * 10/4
	gen st_healthstate			= (healthstate - 1) * 10/4
	gen st_incomeloss			= ((incomeloss +4) * 10/8)-5
	gen st_income_now			= (incomenow - 1) * 10/4

* label standardized variables
	label variable st_acceptance_measures 		"Acceptance of policies to combat Covid-19"
	label variable st_poltrust 				"Political trust"
	label variable st_v_344 					"Social trust"
	label variable st_auto 					"Authoritarianism"
	label variable st_v_42 					"Left = 1; Right = 11"
	label variable st_v_342					"Political interest"
	label variable st_healthstate 				"Overall health status"
	label variable st_incomeloss				"Loss of income"
	label variable st_income_now				"Income situation"	
	
* Descriptive Statistics standardized
	#delimit ;
	outreg2 using "tables\table_1a_standardized" if complete_cases == 1, 
		groupvar( 	Dependent_Variable			st_acceptance_measures
					Trust 						st_poltrust st_v_344 
					Controls_individual_level 	st_auto st_v_42 st_v_342 st_healthstate st_incomeloss hh3andmore male age ohne_hauptschule mittlere_reife fachhochschulreife abitur studium
					Controls_context_level 		inf_7tage_rel_100k inf_14tage_rel_100k	inf_30tage_rel_100k	inf_seit_jan_rel_100k
													tot_7tage_rel_100k tot_14tage_rel_100k tot_30tage_rel_100k tot_seit_jan_rel_100k
													dist_hotspot dist_hotspot_log alq_19 gdp_pc_17) 
													word replace sum(log) label 
													drop(v_505_a complete_cases int_poltrust_auto int_soctrust_leftright alq_18 v_167 gender acceptance_measures poltrust v_344 auto v_42 v_342 healthstate incomeloss ); 	
	#delimit cr  
	
	
* interactions by hand (necesarry for interflex-plots if both interactions with soc trust and pol trust are included)
		gen int_poltrust_auto = st_poltrust * st_auto
		gen int_poltrust_inf_7tage_rel_100k = st_poltrust * inf_7tage_rel_100k	
	
* Distribution of main demographic variables in the sample compared to reality 

* Gender (data from Destatis 12411-0013:  Bevölkerung: Bundesländer, Stichtag, Geschlecht)
gen		str gender2 	= "male" in 1
	replace gender2 	= "female" in 2
	replace gender2 	= "non-binary" in 3
	
gen gender_real			= 48.98583823 in 1
	replace gender_real	= 51.01416177 in 2
	replace gender_real	= 0 in 3

estpost tab gender
mat gender_w1 = e(pct)'	
svmat gender_w1	
rename gender_w11 gender_w1	
replace gender_w1 = . if gender_real == .

label variable gender_real "Official statistics 2020"
label variable gender_w1 "Survey wave 1, May 2020"	
graph bar (asis) gender_real gender_w1, over(gender2) legend(position(1) ring(0)) note("N=8106") ytitle("Percent")
graph save "dump/gender_w1.gph", replace 

* Age (data from Destatis 12411-0013:  Bevölkerung: Bundesländer, Stichtag, Geschlecht)
gen age2 = _n +15
replace age2 = . if age2 > 90

gen age_real = .
replace age_real = 0.010722482633016 if age2 == 16
replace age_real = 0.0107333379451963 if age2 == 17
replace age_real = 0.0109827422669893 if age2 == 18
replace age_real = 0.0114416541138609 if age2 == 19
replace age_real = 0.0122078981757056 if age2 == 20
replace age_real = 0.0124826221607138 if age2 == 21
replace age_real = 0.0128428634492095 if age2 == 22
replace age_real = 0.0134706106450039 if age2 == 23
replace age_real = 0.013429910273232 if age2 == 24
replace age_real = 0.0132381236928424 if age2 == 25
replace age_real = 0.0134439093966021 if age2 == 26
replace age_real = 0.0138787844807889 if age2 == 27
replace age_real = 0.0141086492406575 if age2 == 28
replace age_real = 0.0145922040559591 if age2 == 29
replace age_real = 0.015897083069064 if age2 == 30
replace age_real = 0.0156899439757338 if age2 == 31
replace age_real = 0.0160272199349547 if age2 == 32
replace age_real = 0.0156817531492706 if age2 == 33
replace age_real = 0.0153851070727815 if age2 == 34
replace age_real = 0.0149168483791884 if age2 == 35
replace age_real = 0.0148058140431734 if age2 == 36
replace age_real = 0.0148122144480173 if age2 == 37
replace age_real = 0.0150961865950908 if age2 == 38
replace age_real = 0.0149586906734104 if age2 == 39
replace age_real = 0.0150168159359028 if age2 == 40
replace age_real = 0.0142837158207279 if age2 == 41
replace age_real = 0.0140780147038164 if age2 == 42
replace age_real = 0.0139333148022346 if age2 == 43
replace age_real = 0.0136690231951658 if age2 == 44
replace age_real = 0.0133090074715986 if age2 == 45
replace age_real = 0.013460488418841 if age2 == 46
replace age_real = 0.0135437500730443 if age2 == 47
replace age_real = 0.0146365557600098 if age2 == 48
replace age_real = 0.0160447858037554 if age2 == 49
replace age_real = 0.01660503269472 if age2 == 50
replace age_real = 0.017786048366506 if age2 == 51
replace age_real = 0.0185816299668534 if age2 == 52
replace age_real = 0.0190163358773439 if age2 == 53
replace age_real = 0.0194665916700874 if age2 == 54
replace age_real = 0.0194741058017654 if age2 == 55
replace age_real = 0.019773190799043 if age2 == 56
replace age_real = 0.0195340214858771 if age2 == 57
replace age_real = 0.0188437364136781 if age2 == 58
replace age_real = 0.0184841859177757 if age2 == 59
replace age_real = 0.0177905173716503 if age2 == 60
replace age_real = 0.0171996218460366 if age2 == 61
replace age_real = 0.0161654912360765 if age2 == 62
replace age_real = 0.0156970915644032 if age2 == 63
replace age_real = 0.0151702564784609 if age2 == 64
replace age_real = 0.0145955875298854 if age2 == 65
replace age_real = 0.0142028648916972 if age2 == 66
replace age_real = 0.0136404046448725 if age2 == 67
replace age_real = 0.0135097602578929 if age2 == 68
replace age_real = 0.0131180103684585 if age2 == 69
replace age_real = 0.012994936504389 if age2 == 70
replace age_real = 0.0124236510297398 if age2 == 71
replace age_real = 0.011207870163361 if age2 == 72
replace age_real = 0.0103997838072944 if age2 == 73
replace age_real = 0.0089148475900777 if age2 == 74
replace age_real = 0.00770800473398754 if age2 == 75
replace age_real = 0.0101362816774751 if age2 == 76
replace age_real = 0.0101089460277121 if age2 == 77
replace age_real = 0.00959137320164308 if age2 == 78
replace age_real = 0.0113469873329644 if age2 == 79
replace age_real = 0.0115384778593854 if age2 == 80
replace age_real = 0.010932173429599 if age2 == 81
replace age_real = 0.00969165091013404 if age2 == 82
replace age_real = 0.00852161743080052 if age2 == 83
replace age_real = 0.00767863899986879 if age2 == 84
replace age_real = 0.0068031792192445 if age2 == 85
replace age_real = 0.00572927869284222 if age2 == 86
replace age_real = 0.00410880614926085 if age2 == 87
replace age_real = 0.00360262435207708 if age2 == 88
replace age_real = 0.00319006609799587 if age2 == 89
replace age_real = 0.0118941937515047 if age2 == 90

gen age_w1 = age
label variable age_real "Official statistics 2020"
label variable age_w1 "Survey wave 1, May 2020"

twoway bar age_real age2,  lcolor(gs10) fcolor(gs10) || hist age, width(1)  fcolor(none) lcolor(ebblue) || pcarrowi 0.012 94 0.0118 91  , lcolor(gs6) mcolor(gs6) msize(vsmall) legend(order(1 2 "Survey wave 1, May 2020" ) position(1) ring(0)) note("N=8052") ytitle("Density") xtitle("Age") text(0.0121 96  "90+", color(gs6) size(small)) 
graph save "dump/age_w1.gph", replace

* education (data from Destatis 12211-9012 Allgemeiner Schulabschluss & 12211-9015 Beruflicher Schulabschluss)
gen			edu2 	= 1 in 1
	replace edu2 	= 2 in 2
	replace edu2 	= 3 in 3
	replace edu2 	= 4 in 4
	replace edu2 	= 5 in 5
	
label values edu2 edu 
	
gen edu_real			= 32.62767628 in 1 		// ohne allg. Schulabschluss + Haupt- (Volks-)schulabschluss
	replace edu_real	= 30.02533007 in 2		// polytechnische Oberschule + Realschulabschluss
	replace edu_real	= 0 in 3				// no seperate data available
	replace edu_real	= 18.84755261 in 4		// including Fachhochschulreife (without BA, MA, Diplom, Promotion)
	replace edu_real	= 18.49944104 in 5		// BA, MA, Diplom, Promotion

estpost tab v_505_a
mat edu_w1 = e(pct)'	
svmat edu_w1	
rename edu_w11 edu_w1	
replace edu_w1 = . if edu_real == .

label variable edu_real "Official statistics 2020"
label variable edu_w1 "Survey wave 1, May 2020"	
splitvallabels edu2 , length(20)
graph bar (asis) edu_real edu_w1, over(edu2, relabel(`r(relabel)' )) legend(position(11) ring(0)) note("N=8018") ytitle("Percent") text(9.5 66.3  "including" "Fachhochschulreife" , color(gs3) size(vsmall) orient(vertical))
graph save "dump/edu_w1.gph", replace
 
* federal state (data from Destatis 12411-0013:  Bevölkerung: Bundesländer, Stichtag, Geschlecht)
gen		bundesland2 	= _n
	replace bundesland2 = . if bundesland2 > 16
	label values bundesland2 bundesland

gen bundesland_real = .
replace bundesland_real = 13.2943668979633 if bundesland2 == 1
replace bundesland_real = 15.7953349591959 if bundesland2 == 2
replace bundesland_real = 4.38687413433291 if bundesland2 == 3
replace bundesland_real = 3.06054812587758 if bundesland2 == 4
replace bundesland_real = 0.817753223030298 if bundesland2 == 5
replace bundesland_real = 2.21365896299936 if bundesland2 == 6
replace bundesland_real = 7.54419948296853 if bundesland2 == 7
replace bundesland_real = 1.96128564283601 if bundesland2 == 8
replace bundesland_real = 9.61664352253019 if bundesland2 == 9
replace bundesland_real = 21.4983931388901 if bundesland2 == 10
replace bundesland_real = 4.93859326122239 if bundesland2 == 11
replace bundesland_real = 1.20460835351799 if bundesland2 == 12
replace bundesland_real = 4.90258323018085 if bundesland2 == 13
replace bundesland_real = 2.66760838144575 if bundesland2 == 14
replace bundesland_real = 3.51581568937442 if bundesland2 == 15
replace bundesland_real = 2.58173299363443 if bundesland2 == 16
	
estpost tab bundesland
mat bundesland_w1 = e(pct)'	
svmat bundesland_w1	
rename bundesland_w11 bundesland_w1	
replace bundesland_w1 = . if bundesland_real == .

label variable bundesland_real "Official statistics 2020"
label variable bundesland_w1 "Survey wave 1, May 2020"	
graph hbar (asis) bundesland_real bundesland_w1, over(bundesland2) legend(position(5) ring(0)) note("N=7815") ytitle("Percent")
graph save "dump/bundesland_w1.gph", replace

* party (mean of the following four opinion polls: 
		* 12.May-14.May 2020	Forschungsgruppe Wahlen
		* 04.May-08.May	2020 FORSA
		* 04.May-06.May	2020 Infratest Dimap
		* 23.April-27.April 2020	YouGov
		* source: https://www.wahlrecht.de/umfragen/
		
gen party = v_167
replace party = . if v_167 > 7

gen party2 = _n
replace party2 = . if party2 > 7
label values party2 vote_intent

gen party_real = .
replace party_real = 38.25 if party2 == 1
replace party_real = 15.25 if party2 == 2
replace party_real = 8 if party2 == 3
replace party_real = 17 if party2 == 4
replace party_real = 5.5 if party2 == 5
replace party_real = 10 if party2 == 6
replace party_real = 6 if party2 == 7

estpost tab party
mat party_w1 = e(pct)'	
svmat party_w1	
rename party_w11 party_w1	
replace party_w1 = . if party_real == .

label variable party_real "Opinion polls 23. April-14. May 2020"
label variable party_w1 "Survey wave 1, May 2020"	
graph bar (asis) party_real party_w1, over(party2) legend(position(1) ring(0)) note("N=7504 + 447 'would not vote' + 55 'not eligible'") ytitle("Percent")
graph save "dump/party_w1.gph", replace

	graph combine "dump/gender_w1.gph" "dump/age_w1.gph" "dump/edu_w1.gph" "dump/party_w1.gph", title (Wave 1 May 2020) rows(4)
	graph save "dump/dist_w1.gph", replace
	
* bivariate correlations
	estpost cor st_acceptance_measure st_poltrust st_v_344 st_auto st_v_42 st_v_342 st_healthstate st_incomeloss age if complete_cases == 1, matrix listwise
	esttab using "tables/table_O1a.rtf", unstack  not compress label nostar noobs replace
		
* Models

* 0) empty model
		* a) robust se
		mixed st_acceptance_measures if complete_cases == 1 || NUTS3:, variance robust
		estimates store m0_w1
		estat icc
	
		* b) REML estimation
		mixed st_acceptance_measures if complete_cases == 1 || NUTS3:, variance reml
		estimates store m0_w1_reml
		estat icc	

* 0a) only political trust		
		* a) robust se
		mixed st_acceptance_measures st_poltrust if complete_cases == 1 || NUTS3:, variance robust
		estimates store m0a_w1
	
		* b) REML estimation
		mixed st_acceptance_measures st_poltrust if complete_cases == 1 || NUTS3:, variance reml
		estimates store m0a_w1_reml

* 0b) only social trust		
		* a) robust se
		mixed st_acceptance_measures st_v_344 if complete_cases == 1 || NUTS3:, variance robust
		estimates store m0b_w1
	
		* b) REML estimation
		mixed st_acceptance_measures st_v_344 if complete_cases == 1 || NUTS3:, variance reml
		estimates store m0b_w1_reml

* 0c) only auto		
		* a) robust se
		mixed st_acceptance_measures st_auto if complete_cases == 1 || NUTS3:, variance robust
		estimates store m0c_w1
	
		* b) REML estimation
		mixed st_acceptance_measures st_auto if complete_cases == 1 || NUTS3:, variance reml
		estimates store m0c_w1_reml		

* 0d) only left-right		
		* a) robust se
		mixed st_acceptance_measures st_v_42 if complete_cases == 1 || NUTS3:, variance robust
		estimates store m0d_w1
	
		* b) REML estimation
		mixed st_acceptance_measures st_v_42 if complete_cases == 1 || NUTS3:, variance reml
		estimates store m0d_w1_reml	
		
* 0e) only political interest		
		* a) robust se
		mixed st_acceptance_measures st_v_342 if complete_cases == 1 || NUTS3:, variance robust
		estimates store m0e_w1
	
		* b) REML estimation
		mixed st_acceptance_measures st_v_342 if complete_cases == 1 || NUTS3:, variance reml
		estimates store m0e_w1_reml	
		
* 0f) only healthstate		
		* a) robust se
		mixed st_acceptance_measures st_healthstate if complete_cases == 1 || NUTS3:, variance robust
		estimates store m0f_w1
	
		* b) REML estimation
		mixed st_acceptance_measures st_healthstate if complete_cases == 1 || NUTS3:, variance reml
		estimates store m0f_w1_reml	
		
* 0g) only incomeloss		
		* a) robust se
		mixed st_acceptance_measures st_incomeloss if complete_cases == 1 || NUTS3:, variance robust
		estimates store m0g_w1
	
		* b) REML estimation
		mixed st_acceptance_measures st_incomeloss if complete_cases == 1 || NUTS3:, variance reml
		estimates store m0g_w1_reml			

* 0h) only hh3andmore		
		* a) robust se
		mixed st_acceptance_measures hh3andmore if complete_cases == 1 || NUTS3:, variance robust
		estimates store m0h_w1
	
		* b) REML estimation
		mixed st_acceptance_measures hh3andmore if complete_cases == 1 || NUTS3:, variance reml
		estimates store m0h_w1_reml			

* 0i) only male		
		* a) robust se
		mixed st_acceptance_measures male if complete_cases == 1 || NUTS3:, variance robust
		estimates store m0i_w1
	
		* b) REML estimation
		mixed st_acceptance_measures male if complete_cases == 1 || NUTS3:, variance reml
		estimates store m0i_w1_reml				

* 0j) only age		
		* a) robust se
		mixed st_acceptance_measures age if complete_cases == 1 || NUTS3:, variance robust
		estimates store m0j_w1
	
		* b) REML estimation
		mixed st_acceptance_measures age if complete_cases == 1 || NUTS3:, variance reml
		estimates store m0j_w1_reml				

* 0k) only highest education		
		* a) robust se
		mixed st_acceptance_measures i.v_505_a if complete_cases == 1 || NUTS3:, variance robust
		estimates store m0k_w1
	
		* b) REML estimation
		mixed st_acceptance_measures i.v_505_a if complete_cases == 1 || NUTS3:, variance reml
		estimates store m0k_w1_reml			
		
		
* 1) without interactions (individual level variables only) 
		* a) robust se 
		mixed st_acceptance_measures st_poltrust st_v_344 st_auto  st_v_42 st_v_342 st_healthstate st_incomeloss hh3andmore male age i.v_505_a  || NUTS3:, variance robust
		estimates store m1_w1
		
			*** check mit income_now anstelle von income_loss
			mixed st_acceptance_measures st_poltrust st_v_344 st_auto  st_v_42 st_v_342 st_healthstate st_income_now hh3andmore male age i.v_505_a  || NUTS3:, variance robust
			estimates store m1_w1b
			
			*** check mit income_now & income_loss anstelle von nur income_loss
			mixed st_acceptance_measures st_poltrust st_v_344 st_auto  st_v_42 st_v_342 st_healthstate st_incomeloss st_income_now hh3andmore male age i.v_505_a  || NUTS3:, variance robust
			estimates store m1_w1c
		
		* b) REML estimation
		mixed st_acceptance_measures st_poltrust st_v_344 st_auto  st_v_42 st_v_342 st_healthstate st_incomeloss hh3andmore male age i.v_505_a  || NUTS3:, variance reml
		estimates store m1_w1_reml

* 2) without interactions (including level-2 factors)
		* a) robust se
		mixed st_acceptance_measures st_poltrust st_v_344 st_auto  st_v_42 st_v_342 st_healthstate st_incomeloss hh3andmore male age i.v_505_a inf_7tage_rel_100k tot_7tage_rel_100k dist_hotspot alq_19 gdp_pc_17 || NUTS3:, variance robust
		estimates store m2_w1

		* Betas (nach Hox, J. J., Moerbeek, M., & van de Schoot, R. (2010). Multilevel Analysis: Techniques and Applications, Second Edition. S. 22)
		mixed st_acceptance_measures st_poltrust st_v_344 st_auto  st_v_42 st_v_342 st_healthstate st_incomeloss hh3andmore male age i.v_505_a inf_7tage_rel_100k tot_7tage_rel_100k dist_hotspot alq_19 gdp_pc_17 || NUTS3:, variance robust 
		estadd beta
		matrix beta_w1 = e(beta)
		matrix beta_w1 = beta_w1'
		matrix list beta_w1
		esttab matrix(beta_w1, fmt(3 )) using "dump/betas_w1.rtf", replace label
		
		
			*** check mit income_now anstelle von income_loss
			mixed st_acceptance_measures st_poltrust st_v_344 st_auto  st_v_42 st_v_342 st_healthstate st_income_now hh3andmore male age i.v_505_a inf_7tage_rel_100k tot_7tage_rel_100k dist_hotspot alq_19 gdp_pc_17 if complete_cases == 1 || NUTS3:, variance robust
			estimates store m2_w1b
			
			*** check mit income_now & income_loss anstelle von nur income_loss
			mixed st_acceptance_measures st_poltrust st_v_344 st_auto  st_v_42 st_v_342 st_healthstate st_incomeloss st_income_now hh3andmore male age i.v_505_a inf_7tage_rel_100k tot_7tage_rel_100k dist_hotspot alq_19 gdp_pc_17 || NUTS3:, variance robust
			estimates store m2_w1c
		
		* b) REML estimation
		mixed st_acceptance_measures st_poltrust st_v_344 st_auto  st_v_42 st_v_342 st_healthstate st_incomeloss hh3andmore male age i.v_505_a inf_7tage_rel_100k tot_7tage_rel_100k dist_hotspot alq_19 gdp_pc_17 || NUTS3:, variance reml
		estimates store m2_w1_reml
		
		* c) other operationalizations of the context variables
		mixed st_acceptance_measures st_poltrust st_v_344 st_auto  st_v_42 st_v_342 st_healthstate st_incomeloss hh3andmore male age i.v_505_a inf_14tage_rel_100k tot_14tage_rel_100k dist_hotspot_log alq_19 gdp_pc_17 || NUTS3:, variance robust
		estimates store m2_a_w1
		mixed st_acceptance_measures st_poltrust st_v_344 st_auto  st_v_42 st_v_342 st_healthstate st_incomeloss hh3andmore male age i.v_505_a inf_30tage_rel_100k tot_30tage_rel_100k dist_hotspot_log alq_19 gdp_pc_17 || NUTS3:, variance robust
		estimates store m2_b_w1
		mixed st_acceptance_measures st_poltrust st_v_344 st_auto  st_v_42 st_v_342 st_healthstate st_incomeloss hh3andmore male age i.v_505_a inf_seit_jan_rel_100k tot_seit_jan_rel_100k dist_hotspot_log alq_19 gdp_pc_17 || NUTS3:, variance robust
		estimates store m2_c_w1
		
* 3) full model including 2-way interactions and level 2-factors 
		
		* Option a) nur poltrust * auto
		mixed st_acceptance_measures c.st_poltrust##c.st_auto   st_v_344 c.st_v_42 st_v_342 st_healthstate st_incomeloss hh3andmore male age i.v_505_a inf_7tage_rel_100k tot_7tage_rel_100k dist_hotspot alq_19 gdp_pc_17 || NUTS3:, variance robust
		estimates store m3_w1
		
		mixed st_acceptance_measures c.st_poltrust##c.st_auto   st_v_344 c.st_v_42 st_v_342 st_healthstate st_incomeloss hh3andmore male age i.v_505_a inf_7tage_rel_100k tot_7tage_rel_100k dist_hotspot alq_19 gdp_pc_17 || NUTS3:, variance reml
		estimates store m3_w1_reml
		
		
* Interflex graphs (Outcome Treatment Moderator Covariates)
	
	* poltrust * auto
	interflex st_acceptance_measures st_poltrust st_auto 			st_v_344 st_v_42  st_v_342 st_healthstate st_incomeloss hh3andmore male age mittlere_reife fachhochschulreife abitur studium inf_7tage_rel_100k tot_7tage_rel_100k dist_hotspot alq_19 gdp_pc_17, vce(r) ylab(Acceptance of Covid-19 Policies) nbins(4) dlab(Political Trust) xlab(Authoritanism) title("Wave 1 May 2020")
	graph save "dump/pol_w1a.gph", replace
	
	


* Wave 2 (Oct 29 - Nov 9)
drop *

use "data\corona_wave_2.dta"


* change missing codes 0 --> .

	mvdecode v_556, 	mv(0)
	mvdecode v_557, 	mv(0)
	mvdecode v_344, 	mv(0)
	mvdecode v_42, 		mv(0)
	mvdecode v_342,	 	mv(0)
	mvdecode v_498, 	mv(0)
	mvdecode v_502_a, 	mv(0)
	mvdecode geschlecht,mv(0)
	mvdecode v_505, 	mv(0)
	mvdecode v_363, 	mv(0)
	mvdecode v_364,		mv(0)
	mvdecode v_375, 	mv(0)
	mvdecode v_376, 	mv(0)
	mvdecode v_377, 	mv(0)
	mvdecode v_378, 	mv(0)
	mvdecode v_379, 	mv(0)
	mvdecode v_167,		mv(0)
	mvdecode v_172,		mv(0)
	mvdecode v_173,		mv(0)

* gender including binary
	gen gender = geschlecht
	
* gender = non-binary --> .
	mvdecode geschlecht, mv(3)
	
* still at school --> .
	mvdecode v_505, mv(1)

* recode & calculate variable and label values
	
	* dependent variable: acceptence of anti-Covid-19 policies
	gen acceptance_measures = -(v_556 - 6)
	
	* healthstate
	recode v_498 (1=5) (2=4) (3=3) (4=2) (5=1), gen(healthstate)
	label define healthstate 1 "very bad" 5 "very good"
	label value healthstate healthstate
	
	* incomeloss
	recode v_172 (1=5) (2=4) (3=3) (4=2) (5=1), gen(incomenow)
	label define incomenow 1 "find it very difficult to make ends meet" 5 "can live very comfortably on the income"
	label value incomenow incomenow

	recode v_173 (1=5) (2=4) (3=3) (4=2) (5=1), gen(incomebefore)
	label define incomebefore 1 "find it very difficult to make ends meet" 5 "can live very comfortably on the income"
	label value incomebefore incomevefore

	gen incomeloss = incomebefore-incomenow

	* householdsize 3+
	recode v_502_a (1/2=0) (3/31=1), gen(hh3andmore)
	label define hh3andmore 0 "householdsize < 3" 1 "householdsize >= 3"
	label values hh3andmore hh3andmore
	
	* male
	tab geschlecht, gen(n)
	rename n1 male
	label define male 0 "female" 1 "male"
	label value male male
	
	* gender (including non-binary)
	label define gender 1 "male" 2 "female" 3 "non-binary" 
	label values gender gender
	
	* age
	gen age = 2020 - v_496
	
	* highest educational attainment
	recode v_505 (2/3=1)(4=2)(5=3) (6=4) (7=5), gen (v_505_a)
	label define edu 1 "School dropout & Hauptschulabschluss (ISCED 2)" 2 "Mittlere Reife (ISCED 2)" 3 "Fachhochschulreife (ISCED 3)" 4 "Abitur            (ISCED 3)" 5 "University degree (ISCED 5a)"
	label value v_505_a edu
	
	tab v_505_a, gen(p)
	rename p1 ohne_hauptschule
	rename p2 mittlere_reife
	rename p3 fachhochschulreife
	rename p4 abitur
	rename p5 studium

	* political trust
		* precheck for index construction
		alpha v_363 v_364
		
		* Index using the mean of v_363 and v_364 (standardized to a 1-9-scale)
		gen poltrust = ((v_363 + v_364)/2)*2-1
	
	* authoritarianism
		* precheck for index construction
		pwcorr v_375-v_379, obs sig
		
		factor v_375-v_379
		rotate
		estat kmo
		
		alpha v_375-v_379 
		
		* index using the mean of the five authoritarianism questions
		gen auto = (v_375 + v_376 + v_377 + v_378 + v_379)/5
		
	* voting intention
		label define vote_intent 1 "CDU/CSU" 2 "SPD" 3 "Left Party" 4 "Greens" 5 "FDP" 6 "AfD" 7 "Others" 8 "Would not vote" 9 "Not eligible to vote"
		label values v_167 vote_intent
		
	* level-2 variables:
		
		* infection rates last 7/14/30 days | since January 2020 per 100,000 inhabitants
		gen inf_7tage_rel_100k = inf_7tage_rel*100000
		gen inf_14tage_rel_100k = inf_14tage_rel*100000
		gen inf_30tage_rel_100k = inf_30tage_rel*100000
		gen inf_seit_jan_rel_100k = inf_seit_jan_rel*100000
		
		* Covid-19 related deaths last 7/14/30 days | since January 2020 per 100,000 inhabitants
		gen tot_7tage_rel_100k = tot_7tage_rel*100000
		gen tot_14tage_rel_100k = tot_14tage_rel*100000
		gen tot_30tage_rel_100k = tot_30tage_rel*100000
		gen tot_seit_jan_rel_100k = tot_seit_jan_rel*100000
		
		* log distance hotspot
		rename dist_hotspot_w2_50 dist_hotspot
		gen dist_hotspot_log = log(dist_hotspot)
		
		* GDP per capita
		gen gdp_pc_17 = bip_17/bev_17

	* federal state
	gen bundesland_NUTS = substr(NUTS3,1,3)
	encode bundesland_NUTS, gen(bundesland)
	#delimit ;
	label define bundesland 
		1 "Baden-Wuerttemberg" 
		2 "Bavaria"
		3 "Berlin"
		4 "Brandenburg"
		5 "Bremen"
		6 "Hamburg"
		7 "Hesse"
		8 "Mecklenburg-Vorpommern"
		9 "Lower-Saxony"
		10 "North Rhine-Westpahila"
		11 "Rhineland-Palatinate"
		12 "Saarland"
		13 "Saxony"
		14 "Saxony-Anhalt"
		15 "Schleswig-Holstein"
		16 "Thuringia"	, modify ;
			#delimit cr
	label values bundesland bundesland		
		
		
		
* label variables
	label variable acceptance_measures 		"Acceptance of policies to combat Covid-19"
	label variable poltrust 				"Political trust"
	label variable v_344 					"Social trust"
	label variable auto 					"Authoritarianism"
	label variable v_42 					"Left = 1; Right = 11"
	label variable v_167					"Voting intention"
	label variable v_342					"Political interest"
	label variable healthstate 				"Overall health status"
	label variable incomeloss				"Loss of income"
	label variable hh3andmore				"Household 3+ (dummy)"
	label variable male						"Male"
	label variable gender					"Gender"
	label variable age						"Age"
	label variable v_505_a					"Highest educational attainment"
	label variable ohne_hauptschule 		"School dropout/Hauptschulabschluss (ISCED 2)"
	label variable mittlere_reife			"Mittlere Reife (ISCED 2)"
	label variable fachhochschulreife  		"Fachhochschulreife (ISCED 3)"
	label variable abitur 					"Abitur (ISCED 3)"
	label variable studium					"University degree (ISCED 5a)"
	label variable inf_7tage_rel_100k		"# Covid-19 cases last 7 days per 100,000 inhabitants"
	label variable inf_14tage_rel_100k		"# Covid-19 cases last 14 days per 100,000 inhabitants"
	label variable inf_30tage_rel_100k		"# Covid-19 cases last 30 days per 100,000 inhabitants"
	label variable inf_seit_jan_rel_100k	"# Covid-19 cases since January 2020 per 100,000 inhabitants"
	label variable tot_7tage_rel_100k		"# Covid-19 deaths last 7 days per 100,000 inhabitants"
	label variable tot_14tage_rel_100k		"# Covid-19 deaths last 14 days per 100,000 inhabitants"
	label variable tot_30tage_rel_100k		"# Covid-19 deaths last 30 days per 100,000 inhabitants"
	label variable tot_seit_jan_rel_100k	"# Covid-19 deaths since January 2020 per 100,000 inhabitants"
	label variable dist_hotspot				"Distance to nearest hotspot (in km)"
	label variable dist_hotspot_log			"Log distance to nearest hotspot (in km)"
	label variable alq_18					"Unemployment rate (2018, in %)"
	label variable alq_19					"Unemployment rate (2019, in %)"
	label variable gdp_pc_17				"GDP per capita (2017, in thousand Euro)"

*keep 
	#delimit ;
	keep 	acceptance_measures 	
			poltrust				
			v_344					
			auto					
			v_42					
			v_167					
			v_342					
			healthstate				
			incomeloss	
			incomenow
			hh3andmore				
			male	
			gender
			age						
			v_505_a					
			ohne_hauptschule		
			mittlere_reife			
			fachhochschulreife		
			abitur					
			studium					
			inf_7tage_rel_100k		
			inf_14tage_rel_100k		
			inf_30tage_rel_100k		
			inf_seit_jan_rel_100k	
			tot_7tage_rel_100k		
			tot_14tage_rel_100k		
			tot_30tage_rel_100k		
			tot_seit_jan_rel_100k	
			dist_hotspot
			dist_hotspot_log
			alq_18					
			alq_19					
			gdp_pc_17
			NUTS3 
			bundesland;
			#delimit cr
			
* Missing Table
misstable summ	
				
* generate filter variable for no missing cases in the following regression models

	gen complete_cases = 0
	
	#delim ;
	replace complete_cases = 1 if 	acceptance_measures 	!= . &
								poltrust				!= . &
								v_344					!= . &
								auto					!= . &
								v_42					!= . &
								v_42					!= .b&
								v_342					!= . &
								healthstate				!= . &
								incomeloss				!= . &
								incomenow				!= . &
								hh3andmore				!= . &
								male					!= . &
								age						!= . &
								v_505_a					!= . &
								ohne_hauptschule		!= . &
								mittlere_reife			!= . &
								fachhochschulreife		!= . &
								abitur					!= . &
								studium					!= . &
								inf_7tage_rel_100k		!= . &
								inf_14tage_rel_100k		!= . &
								inf_30tage_rel_100k		!= . &
								inf_seit_jan_rel_100k	!= . &
								tot_7tage_rel_100k		!= . &
								tot_14tage_rel_100k		!= . &
								tot_30tage_rel_100k		!= . &
								tot_seit_jan_rel_100k	!= . &
								dist_hotspot			!= . &
								alq_18					!= . &
								alq_19					!= . &
								gdp_pc_17				!= . &
								NUTS3					!= "" ;
				#delimit cr


	* Standardization of survey-variables 0-10
	gen st_acceptance_measures 	= (acceptance_measures - 1)*10/4
	gen st_poltrust 			= (poltrust - 1)*10/8
	gen st_v_344				= (v_344 - 1) * 10/6
	gen st_auto					= (auto - 1) * 10/4
	gen st_v_42					= (v_42 - 1) * 10/10
	gen st_v_342				= (v_342 - 1) * 10/4
	gen st_healthstate			= (healthstate - 1) * 10/4
	gen st_incomeloss			= ((incomeloss +4) * 10/8)-5
	gen st_income_now			= (incomenow - 1) * 10/4

* label standardized variables
	label variable st_acceptance_measures 		"Acceptance of policies to combat Covid-19"
	label variable st_poltrust 				"Political trust"
	label variable st_v_344 					"Social trust"
	label variable st_auto 					"Authoritarianism"
	label variable st_v_42 					"Left = 1; Right = 11"
	label variable st_v_342					"Political interest"
	label variable st_healthstate 				"Overall health status"
	label variable st_incomeloss				"Loss of income"	
	label variable st_income_now				"Income situation"	
	
* Descriptive Statistics standardized
	#delimit ;
	outreg2 using "tables\table_1b_standardized" if complete_cases == 1, 
		groupvar( 	Dependent_Variable			st_acceptance_measures
					Trust 						st_poltrust st_v_344 
					Controls_individual_level 	st_auto st_v_42 st_v_342 st_healthstate st_incomeloss hh3andmore male age ohne_hauptschule mittlere_reife fachhochschulreife abitur studium
					Controls_context_level 		inf_7tage_rel_100k inf_14tage_rel_100k	inf_30tage_rel_100k	inf_seit_jan_rel_100k
													tot_7tage_rel_100k tot_14tage_rel_100k tot_30tage_rel_100k tot_seit_jan_rel_100k
													dist_hotspot dist_hotspot_log alq_19 gdp_pc_17) 
													word replace sum(log) label 
													drop(v_505_a complete_cases int_poltrust_auto int_soctrust_leftright alq_18 v_167 gender acceptance_measures poltrust v_344 auto v_42 v_342 healthstate incomeloss ); 	
	#delimit cr  
	
* interactions by hand (necesarry for interflex-plots if both interactions with soc trust and pol trust are included)
		gen int_poltrust_auto = st_poltrust * st_auto
		gen int_poltrust_inf_7tage_rel_100k = st_poltrust * inf_7tage_rel_100k		
	
	** correlation social-political trust
	corr poltrust v_344 if complete_cases == 1	

* Distribution of main demographic variables in the sample compared to reality 

* Gender (data from Destatis 12411-0013:  Bevölkerung: Bundesländer, Stichtag, Geschlecht)
gen		str gender2 	= "male" in 1
	replace gender2 	= "female" in 2
	replace gender2 	= "non-binary" in 3
	
gen gender_real			= 48.98583823 in 1
	replace gender_real	= 51.01416177 in 2
	replace gender_real	= 0 in 3

estpost tab gender
mat gender_w2 = e(pct)'	
svmat gender_w2	
rename gender_w21 gender_w2	
replace gender_w2 = . if gender_real == .

label variable gender_real "Official statistics 2020"
label variable gender_w2 "Survey wave 2, Nov 2020"	
graph bar (asis) gender_real gender_w2, over(gender2) legend(position(1) ring(0)) note("N=6815") ytitle("Percent")
graph save "dump/gender_w2.gph", replace

* Age (data from Destatis 12411-0013:  Bevölkerung: Bundesländer, Stichtag, Geschlecht)
gen age2 = _n +15
replace age2 = . if age2 > 90

gen age_real = .
replace age_real = 0.010722482633016 if age2 == 16
replace age_real = 0.0107333379451963 if age2 == 17
replace age_real = 0.0109827422669893 if age2 == 18
replace age_real = 0.0114416541138609 if age2 == 19
replace age_real = 0.0122078981757056 if age2 == 20
replace age_real = 0.0124826221607138 if age2 == 21
replace age_real = 0.0128428634492095 if age2 == 22
replace age_real = 0.0134706106450039 if age2 == 23
replace age_real = 0.013429910273232 if age2 == 24
replace age_real = 0.0132381236928424 if age2 == 25
replace age_real = 0.0134439093966021 if age2 == 26
replace age_real = 0.0138787844807889 if age2 == 27
replace age_real = 0.0141086492406575 if age2 == 28
replace age_real = 0.0145922040559591 if age2 == 29
replace age_real = 0.015897083069064 if age2 == 30
replace age_real = 0.0156899439757338 if age2 == 31
replace age_real = 0.0160272199349547 if age2 == 32
replace age_real = 0.0156817531492706 if age2 == 33
replace age_real = 0.0153851070727815 if age2 == 34
replace age_real = 0.0149168483791884 if age2 == 35
replace age_real = 0.0148058140431734 if age2 == 36
replace age_real = 0.0148122144480173 if age2 == 37
replace age_real = 0.0150961865950908 if age2 == 38
replace age_real = 0.0149586906734104 if age2 == 39
replace age_real = 0.0150168159359028 if age2 == 40
replace age_real = 0.0142837158207279 if age2 == 41
replace age_real = 0.0140780147038164 if age2 == 42
replace age_real = 0.0139333148022346 if age2 == 43
replace age_real = 0.0136690231951658 if age2 == 44
replace age_real = 0.0133090074715986 if age2 == 45
replace age_real = 0.013460488418841 if age2 == 46
replace age_real = 0.0135437500730443 if age2 == 47
replace age_real = 0.0146365557600098 if age2 == 48
replace age_real = 0.0160447858037554 if age2 == 49
replace age_real = 0.01660503269472 if age2 == 50
replace age_real = 0.017786048366506 if age2 == 51
replace age_real = 0.0185816299668534 if age2 == 52
replace age_real = 0.0190163358773439 if age2 == 53
replace age_real = 0.0194665916700874 if age2 == 54
replace age_real = 0.0194741058017654 if age2 == 55
replace age_real = 0.019773190799043 if age2 == 56
replace age_real = 0.0195340214858771 if age2 == 57
replace age_real = 0.0188437364136781 if age2 == 58
replace age_real = 0.0184841859177757 if age2 == 59
replace age_real = 0.0177905173716503 if age2 == 60
replace age_real = 0.0171996218460366 if age2 == 61
replace age_real = 0.0161654912360765 if age2 == 62
replace age_real = 0.0156970915644032 if age2 == 63
replace age_real = 0.0151702564784609 if age2 == 64
replace age_real = 0.0145955875298854 if age2 == 65
replace age_real = 0.0142028648916972 if age2 == 66
replace age_real = 0.0136404046448725 if age2 == 67
replace age_real = 0.0135097602578929 if age2 == 68
replace age_real = 0.0131180103684585 if age2 == 69
replace age_real = 0.012994936504389 if age2 == 70
replace age_real = 0.0124236510297398 if age2 == 71
replace age_real = 0.011207870163361 if age2 == 72
replace age_real = 0.0103997838072944 if age2 == 73
replace age_real = 0.0089148475900777 if age2 == 74
replace age_real = 0.00770800473398754 if age2 == 75
replace age_real = 0.0101362816774751 if age2 == 76
replace age_real = 0.0101089460277121 if age2 == 77
replace age_real = 0.00959137320164308 if age2 == 78
replace age_real = 0.0113469873329644 if age2 == 79
replace age_real = 0.0115384778593854 if age2 == 80
replace age_real = 0.010932173429599 if age2 == 81
replace age_real = 0.00969165091013404 if age2 == 82
replace age_real = 0.00852161743080052 if age2 == 83
replace age_real = 0.00767863899986879 if age2 == 84
replace age_real = 0.0068031792192445 if age2 == 85
replace age_real = 0.00572927869284222 if age2 == 86
replace age_real = 0.00410880614926085 if age2 == 87
replace age_real = 0.00360262435207708 if age2 == 88
replace age_real = 0.00319006609799587 if age2 == 89
replace age_real = 0.0118941937515047 if age2 == 90

gen age_w2 = age
label variable age_real "Official statistics 2020"
label variable age_w2 "Survey wave 2, Nov 2020"

twoway bar age_real age2,  lcolor(gs10) fcolor(gs10) || hist age, width(1)  fcolor(none) lcolor(ebblue) || pcarrowi 0.012 94 0.0118 91  , lcolor(gs6) mcolor(gs6) msize(vsmall)  legend(order(1 2 "Survey wave 2, Nov 2020" ) position(1) ring(0)) note("N=6797") ytitle("Density") xtitle("Age") text(0.0121 96  "90+", color(gs6) size(small)) 
graph save "dump/age_w2.gph", replace

* education (data from Destatis 12211-9012 Allgemeiner Schulabschluss & 12211-9015 Beruflicher Schulabschluss)
gen			edu2 	= 1 in 1
	replace edu2 	= 2 in 2
	replace edu2 	= 3 in 3
	replace edu2 	= 4 in 4
	replace edu2 	= 5 in 5
	
label values edu2 edu 
	
gen edu_real			= 32.62767628 in 1 		// ohne allg. Schulabschluss + Haupt- (Volks-)schulabschluss
	replace edu_real	= 30.02533007 in 2		// polytechnische Oberschule + Realschulabschluss
	replace edu_real	= 0 in 3				// no seperate data available
	replace edu_real	= 18.84755261 in 4		// including Fachhochschulreife (without BA, MA, Diplom, Promotion)
	replace edu_real	= 18.49944104 in 5		// BA, MA, Diplom, Promotion

estpost tab v_505_a
mat edu_w2 = e(pct)'	
svmat edu_w2	
rename edu_w21 edu_w2	
replace edu_w2 = . if edu_real == .

label variable edu_real "Official statistics 2020"
label variable edu_w2 "Survey wave 2, Nov 2020"	
splitvallabels edu2 , length(20)
graph bar (asis) edu_real edu_w2, over(edu2, relabel(`r(relabel)' )) legend(position(11) ring(0)) note("N=6781") ytitle("Percent") text(9.5 66.3  "including" "Fachhochschulreife" , color(gs3) size(vsmall) orient(vertical))
graph save "dump/edu_w2.gph", replace
 
* federal state (data from Destatis 12411-0013:  Bevölkerung: Bundesländer, Stichtag, Geschlecht)
gen		bundesland2 	= _n
	replace bundesland2 = . if bundesland2 > 16
	label values bundesland2 bundesland

gen bundesland_real = .
replace bundesland_real = 13.2943668979633 if bundesland2 == 1
replace bundesland_real = 15.7953349591959 if bundesland2 == 2
replace bundesland_real = 4.38687413433291 if bundesland2 == 3
replace bundesland_real = 3.06054812587758 if bundesland2 == 4
replace bundesland_real = 0.817753223030298 if bundesland2 == 5
replace bundesland_real = 2.21365896299936 if bundesland2 == 6
replace bundesland_real = 7.54419948296853 if bundesland2 == 7
replace bundesland_real = 1.96128564283601 if bundesland2 == 8
replace bundesland_real = 9.61664352253019 if bundesland2 == 9
replace bundesland_real = 21.4983931388901 if bundesland2 == 10
replace bundesland_real = 4.93859326122239 if bundesland2 == 11
replace bundesland_real = 1.20460835351799 if bundesland2 == 12
replace bundesland_real = 4.90258323018085 if bundesland2 == 13
replace bundesland_real = 2.66760838144575 if bundesland2 == 14
replace bundesland_real = 3.51581568937442 if bundesland2 == 15
replace bundesland_real = 2.58173299363443 if bundesland2 == 16
	
estpost tab bundesland
mat bundesland_w2 = e(pct)'	
svmat bundesland_w2	
rename bundesland_w21 bundesland_w2	
replace bundesland_w2 = . if bundesland_real == .

label variable bundesland_real "Official statistics 2020"
label variable bundesland_w2 "Survey wave 2, Nov 2020"	
graph hbar (asis) bundesland_real bundesland_w2, over(bundesland2) legend(position(5) ring(0)) note("N=6609") ytitle("Percent")
graph save "dump/bundesland_w2.gph", replace

* party (mean of the following four opinion polls: 
		* 12.May-14.May 2020	Forschungsgruppe Wahlen
		* 04.May-08.May	2020 FORSA
		* 04.May-06.May	2020 Infratest Dimap
		* 23.April-27.April 2020	YouGov
		* source: https://www.wahlrecht.de/umfragen/
		
gen party = v_167
replace party = . if v_167 > 7

gen party2 = _n
replace party2 = . if party2 > 7
label values party2 vote_intent

gen party_real = .
replace party_real = 35 if party2 == 1
replace party_real = 15.5 if party2 == 2
replace party_real = 8 if party2 == 3
replace party_real = 19 if party2 == 4
replace party_real = 6 if party2 == 5
replace party_real = 10.75 if party2 == 6
replace party_real = 5.75 if party2 == 7

estpost tab party
mat party_w2 = e(pct)'	
svmat party_w2	
rename party_w21 party_w2	
replace party_w2 = . if party_real == .

label variable party_real "Opinion polls 12-30. October 2020"
label variable party_w2 "Survey wave 2, Nov 2020"	
graph bar (asis) party_real party_w2, over(party2) legend(position(1) ring(0)) note("N=6380 + 305 'would not vote' + 36 'not eligible'") ytitle("Percent")
graph save "dump/party_w2.gph", replace
	
	graph combine "dump/gender_w2.gph" "dump/age_w2.gph" "dump/edu_w2.gph" "dump/party_w2.gph", title (Wave 2 Nov 2020) rows(4)
	graph save "dump/dist_w2.gph", replace
	
	
* bivariate correlations
	estpost cor st_acceptance_measure st_poltrust st_v_344 st_auto st_v_42 st_v_342 st_healthstate st_incomeloss age if complete_cases == 1, matrix listwise
	esttab using "tables/table_O1b.rtf", unstack  not compress label nostar noobs replace
	  
* Models

* 0) empty model
		* a) robust se
		mixed st_acceptance_measures if complete_cases == 1 || NUTS3:, variance robust
		estimates store m0_w2
		estat icc
	
		* b) REML estimation
		mixed st_acceptance_measures if complete_cases == 1 || NUTS3:, variance reml
		estimates store m0_w2_reml
		estat icc	

* 0a) only political trust		
		* a) robust se
		mixed st_acceptance_measures st_poltrust if complete_cases == 1 || NUTS3:, variance robust
		estimates store m0a_w2
	
		* b) REML estimation
		mixed st_acceptance_measures st_poltrust if complete_cases == 1 || NUTS3:, variance reml
		estimates store m0a_w2_reml

* 0b) only social trust		
		* a) robust se
		mixed st_acceptance_measures st_v_344 if complete_cases == 1 || NUTS3:, variance robust
		estimates store m0b_w2
	
		* b) REML estimation
		mixed st_acceptance_measures st_v_344 if complete_cases == 1 || NUTS3:, variance reml
		estimates store m0b_w2_reml

* 0c) only auto		
		* a) robust se
		mixed st_acceptance_measures st_auto if complete_cases == 1 || NUTS3:, variance robust
		estimates store m0c_w2
	
		* b) REML estimation
		mixed st_acceptance_measures st_auto if complete_cases == 1 || NUTS3:, variance reml
		estimates store m0c_w2_reml		

* 0d) only left-right		
		* a) robust se
		mixed st_acceptance_measures st_v_42 if complete_cases == 1 || NUTS3:, variance robust
		estimates store m0d_w2
	
		* b) REML estimation
		mixed st_acceptance_measures st_v_42 if complete_cases == 1 || NUTS3:, variance reml
		estimates store m0d_w2_reml	
		
* 0e) only political interest		
		* a) robust se
		mixed st_acceptance_measures st_v_342 if complete_cases == 1 || NUTS3:, variance robust
		estimates store m0e_w2
	
		* b) REML estimation
		mixed st_acceptance_measures st_v_342 if complete_cases == 1 || NUTS3:, variance reml
		estimates store m0e_w2_reml	
		
* 0f) only healthstate		
		* a) robust se
		mixed st_acceptance_measures st_healthstate if complete_cases == 1 || NUTS3:, variance robust
		estimates store m0f_w2
	
		* b) REML estimation
		mixed st_acceptance_measures st_healthstate if complete_cases == 1 || NUTS3:, variance reml
		estimates store m0f_w2_reml	
		
* 0g) only incomeloss		
		* a) robust se
		mixed st_acceptance_measures st_incomeloss if complete_cases == 1 || NUTS3:, variance robust
		estimates store m0g_w2
	
		* b) REML estimation
		mixed st_acceptance_measures st_incomeloss if complete_cases == 1 || NUTS3:, variance reml
		estimates store m0g_w2_reml			

* 0h) only hh3andmore		
		* a) robust se
		mixed st_acceptance_measures hh3andmore if complete_cases == 1 || NUTS3:, variance robust
		estimates store m0h_w2
	
		* b) REML estimation
		mixed st_acceptance_measures hh3andmore if complete_cases == 1 || NUTS3:, variance reml
		estimates store m0h_w2_reml			

* 0i) only male		
		* a) robust se
		mixed st_acceptance_measures male if complete_cases == 1 || NUTS3:, variance robust
		estimates store m0i_w2
	
		* b) REML estimation
		mixed st_acceptance_measures male if complete_cases == 1 || NUTS3:, variance reml
		estimates store m0i_w2_reml				

* 0j) only age		
		* a) robust se
		mixed st_acceptance_measures age if complete_cases == 1 || NUTS3:, variance robust
		estimates store m0j_w2
	
		* b) REML estimation
		mixed st_acceptance_measures age if complete_cases == 1 || NUTS3:, variance reml
		estimates store m0j_w2_reml				

* 0k) only highest education		
		* a) robust se
		mixed st_acceptance_measures i.v_505_a if complete_cases == 1 || NUTS3:, variance robust
		estimates store m0k_w2
	
		* b) REML estimation
		mixed st_acceptance_measures i.v_505_a if complete_cases == 1 || NUTS3:, variance reml
		estimates store m0k_w2_reml			
		
		
* 1) without interactions (individual level variables only) 
		* a) robust se 
		mixed st_acceptance_measures st_poltrust st_v_344 st_auto  st_v_42 st_v_342 st_healthstate st_incomeloss hh3andmore male age i.v_505_a  || NUTS3:, variance robust
		estimates store m1_w2
		
		* b) REML estimation
		mixed st_acceptance_measures st_poltrust st_v_344 st_auto  st_v_42 st_v_342 st_healthstate st_incomeloss hh3andmore male age i.v_505_a  || NUTS3:, variance reml
		estimates store m1_w2_reml

* 2) without interactions (including level-2 factors)
		* a) robust se
		mixed st_acceptance_measures st_poltrust st_v_344 st_auto  st_v_42 st_v_342 st_healthstate st_incomeloss hh3andmore male age i.v_505_a inf_7tage_rel_100k tot_7tage_rel_100k dist_hotspot alq_19 gdp_pc_17 || NUTS3:, variance robust
		estimates store m2_w2
		
		* Betas (nach Hox, J. J., Moerbeek, M., & van de Schoot, R. (2010). Multilevel Analysis: Techniques and Applications, Second Edition. S. 22)
		mixed st_acceptance_measures st_poltrust st_v_344 st_auto  st_v_42 st_v_342 st_healthstate st_incomeloss hh3andmore male age i.v_505_a inf_7tage_rel_100k tot_7tage_rel_100k dist_hotspot alq_19 gdp_pc_17 || NUTS3:, variance robust 
		estadd beta
		matrix beta_w2 = e(beta)
		matrix beta_w2 = beta_w2'
		matrix list beta_w2
		esttab matrix(beta_w2, fmt(3 )) using "dump/betas_w2.rtf", replace label
		
		
			*** check mit income_now anstelle von income_loss
			mixed st_acceptance_measures st_poltrust st_v_344 st_auto  st_v_42 st_v_342 st_healthstate st_income_now hh3andmore male age i.v_505_a inf_7tage_rel_100k tot_7tage_rel_100k dist_hotspot alq_19 gdp_pc_17 if complete_cases == 1 || NUTS3:, variance robust
			estimates store m2_w2b
			
			*** check mit income_now & income_loss anstelle von nur income_loss
			mixed st_acceptance_measures st_poltrust st_v_344 st_auto  st_v_42 st_v_342 st_healthstate st_incomeloss st_income_now hh3andmore male age i.v_505_a inf_7tage_rel_100k tot_7tage_rel_100k dist_hotspot alq_19 gdp_pc_17 if complete_cases == 1 || NUTS3:, variance robust
			estimates store m2_w2c	
		
		* b) REML estimation
		mixed st_acceptance_measures st_poltrust st_v_344 st_auto  st_v_42 st_v_342 st_healthstate st_incomeloss hh3andmore male age i.v_505_a inf_7tage_rel_100k tot_7tage_rel_100k dist_hotspot alq_19 gdp_pc_17 || NUTS3:, variance reml
		estimates store m2_w2_reml
		
		* c) other operationalizations of the context variables
		mixed st_acceptance_measures st_poltrust st_v_344 st_auto  st_v_42 st_v_342 st_healthstate st_incomeloss hh3andmore male age i.v_505_a inf_14tage_rel_100k tot_14tage_rel_100k dist_hotspot_log alq_19 gdp_pc_17 || NUTS3:, variance robust
		estimates store m2_a_w2
		mixed st_acceptance_measures st_poltrust st_v_344 st_auto  st_v_42 st_v_342 st_healthstate st_incomeloss hh3andmore male age i.v_505_a inf_30tage_rel_100k tot_30tage_rel_100k dist_hotspot_log alq_19 gdp_pc_17 || NUTS3:, variance robust
		estimates store m2_b_w2
		mixed st_acceptance_measures st_poltrust st_v_344 st_auto  st_v_42 st_v_342 st_healthstate st_incomeloss hh3andmore male age i.v_505_a inf_seit_jan_rel_100k tot_seit_jan_rel_100k dist_hotspot_log alq_19 gdp_pc_17 || NUTS3:, variance robust
		estimates store m2_c_w2
		

* 3) full model including 2-way interactions and level 2-factors 
		
		* poltrust * auto
		mixed st_acceptance_measures c.st_poltrust##c.st_auto   st_v_344 c.st_v_42 st_v_342 st_healthstate st_incomeloss hh3andmore male age i.v_505_a inf_7tage_rel_100k tot_7tage_rel_100k dist_hotspot alq_19 gdp_pc_17 || NUTS3:, variance robust
		estimates store m3_w2
		

		
		mixed st_acceptance_measures c.st_poltrust##c.st_auto   st_v_344 c.st_v_42 st_v_342 st_healthstate st_incomeloss hh3andmore male age i.v_505_a inf_7tage_rel_100k tot_7tage_rel_100k dist_hotspot alq_19 gdp_pc_17 || NUTS3:, variance reml
		estimates store m3_w2_reml
				
		
* Interflex graphs (Outcome Treatment Moderator Covariates)
	
	* poltrust * auto
	interflex st_acceptance_measures st_poltrust st_auto 			st_v_344 st_v_42  st_v_342 st_healthstate st_incomeloss hh3andmore male age mittlere_reife fachhochschulreife abitur studium inf_7tage_rel_100k tot_7tage_rel_100k dist_hotspot alq_19 gdp_pc_17, vce(r) ylab(Acceptance of Covid-19 Policies) nbins(4) dlab(Political Trust) xlab(Authoritanism) title("Wave 2 Nov 2020")
	graph save "dump/pol_w2a.gph", replace
	
		
* Figures		
	
	* Figure 1: Distribution (age, gender, education, voting intention)
	graph combine "dump/dist_w1.gph" "dump/dist_w2.gph", col(2) ysize(10) xsize(9) iscale(.45)
	graph export "figures/figure_1.pdf", replace
	graph export "figures/figure_1.emf", replace

	* Figure A1
	graph combine "dump/bundesland_w1.gph" "dump/bundesland_w2.gph", col(1) ysize(10) xsize(9) iscale(.45)
	graph export "figures/figure_O1.pdf", replace
	graph export "figures/figure_O1.emf", replace

	
	* Figure 2: Coefplots models 2 and 3 
	* poltrust * auto
	# delimit ;
	coefplot 	(m2_w1, label(Main effects model) )  	(m3_w1, label(Interaction model) )  , bylabel(Wave 1 May 2020) ||
				(m2_w2)  	(m3_w2 )  , bylabel(Wave 2 Nov 2020) ||, 
				drop(_cons) xline(0) headings(st_poltrust="{bf:Trust}" st_auto="{bf:Controls individual level}" c.st_poltrust#c.st_auto="{bf:Interaction}" inf_7tage_rel_100k="{bf:Controls context level}")	
				order(st_poltrust st_v_344 c.st_poltrust#c.st_auto st_auto st_v_42 st_v_342 st_healthstate st_incomeloss hh3andmore male age v_505_a) 
				coeflabels(c.st_poltrust#c.st_auto="Political Trust x Authoritarianism" )
				legend(rows(1));
	#delimit cr
	graph export "figures/figure_2.pdf", replace
	graph export "figures/figure_2.emf", replace
	
	
	* Figure 3: Interflex-Plots
	* Option a) only poltrust * auto 
	graph combine "dump/pol_w1a.gph" "dump/pol_w2a.gph", rows(1) iscale(.65) 
	graph export "figures/figure_3.pdf", replace 
	graph export "figures/figure_3.emf", replace
	
	
* Regression tables

	* Table 2: complete model building for models in Figure 1 
	esttab m0_w1 m0a_w1 m0b_w1 m1_w1 m2_w1 m3_w1 m0_w2 m0a_w2 m0b_w2 m1_w2 m2_w2 m3_w2 using "tables/table_2.rtf", se aic bic replace label
	
	* Table O1: missing values see above code
	
	* Table O2: correlation matrix see above code
	
	* Table O3: bivariate regressions for all control variables wave 1
	esttab m0c_w1 m0d_w1 m0e_w1 m0f_w1 m0g_w1 m0h_w1 m0i_w1 m0j_w1 m0k_w1 using "tables/table_O3.rtf", se aic bic replace label
	
	* Table O4: bivariate regressions for all control variables wave 2
	esttab m0c_w2 m0d_w2 m0e_w2 m0f_w2 m0g_w2 m0h_w2 m0i_w2 m0j_w2 m0k_w2 using "tables/table_O4.rtf", se aic bic replace label
	
	* Table O5: REML models 
	esttab m0_w1_reml m0a_w1_reml m0b_w1_reml m1_w1_reml m2_w1_reml m3_w1_reml m0_w2_reml m0a_w2_reml m0b_w2_reml m1_w2_reml m2_w2_reml m3_w2_reml using "tables/table_O5.rtf", se aic bic replace label
	
	* Table O6: income situation vs. income loss
	esttab m2_w1 m2_w1b m2_w1c m2_w2 m2_w2b m2_w2c using "tables/table_O6.rtf", se aic bic replace label
	
	* Table O7: different operationalization for context factors
	esttab m2_a_w1 m2_b_w1 m2_c_w1 m2_a_w2 m2_b_w2 m2_c_w2 using "tables/table_O7.rtf", se aic bic replace label
	
	* Table O8: Betas des finalen Modells ohne Interaktionen
		* Kombination der beiden Beta-Matrizen
		matrix beta_final = beta_w1, beta_w2
		esttab matrix(beta_final, fmt(3 3)) using "tables/table_O8.rtf", replace label
